/**
 * Theme: Moltran Admin Template
 * Author: Coderthemes
 * Module/App: Dashboard
 */
var prefix = ctx + "manage/adRecord";

function search() {
    var params = {
        // 传递参数查询参数
        channel: $("#arChannel option:selected").val(),
        usId: $("#usId").val(),
        createTime: $("#createTime").val()
    };
    _ajax_query(prefix + "/list_hour", params, callback);
}
function resetForm() {
    cmResetForm();
    var startCreatTime = moment().hours(0).minutes(0).seconds(0);
    $('#createTime').val(startCreatTime.format('YYYY-MM-DD'));
    search();
}

function callback(result) {
    var adRecordSum = result.adRecordSum / 10000;
    var adRecordSecondarySum = result.adRecordSecondarySum / 10000;
    $('label#adRecordSum').html("主广金币：" + formatNumber(result.adRecordSum) + "<span class='text-danger'>≈" + adRecordSum + "元</span>");
    $('label#adRecordSecondarySum').html("副广金币：" + formatNumber(result.adRecordSecondarySum)  + "<span class='text-danger'>≈" + adRecordSecondarySum + "元</span>");
    $('#website-stats').empty();
    !function($) {
        "use strict";
        var Dashboard = function() {
            this.$body = $("body");
            this.$realData = []
        };
        //creates Pie Chart
        Dashboard.prototype.createPieGraph = function(selector, labels, datas, colors) {
            var data = [{
                label: labels[0],
                data: datas[0]
            }, {
                label: labels[1],
                data: datas[1]
            }, {
                label: labels[2],
                data: datas[2]
            }];
            var options = {
                series: {
                    pie: {
                        show: true
                    }
                },
                legend : {
                    show : false
                },
                grid : {
                    hoverable : true,
                    clickable : true
                },
                colors : colors,
                tooltip : true,
                tooltipOpts : {
                    content : "%s, %p.0%"
                }
            };

            $.plot($(selector), data, options);
        },

            //initializing various charts and components
            Dashboard.prototype.init = function() {
                Morris.Line({
                    element: 'website-stats',
                    data:result.adRecordList,
                    xkey: 'y',
                    ykeys: ['a', 'b'],
                    stacked: false,
                    labels: ['主广', '副广'],
                    lineColors: ['#29b6f6','#6e8cd7'],
                    fillColor: 'rgba(30, 136, 229, 0.3)',
                    composite: true,
                    highlightLineColor: 'rgba(0,0,0,.1)',
                    highlightSpotColor: 'rgba(0,0,0,.2)',
                });

                var pielabels = ["穿山甲","优量汇","快手"];
                var datas = [20,30, 20];
                var colors = ["rgba(30, 136, 229, 0.85)", "rgba(41, 182, 246, 0.85)", "rgba(126, 87, 194, 0.85)"];
                this.createPieGraph("#pie-chart #pie-chart-container", pielabels , datas, colors);

            },

            //init Dashboard
            $.Dashboard = new Dashboard, $.Dashboard.Constructor = Dashboard

    }(window.jQuery),

//initializing Dashboard
        function($) {
            "use strict";
            $.Dashboard.init()
        }(window.jQuery);
}
